from rest_framework.viewsets import ModelViewSet
from rest_framework.filters import OrderingFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.pagination import PageNumberPagination
from app01.sers import User,UserSer


class MyPage(PageNumberPagination):
    page_size_query_param = "max_page"
    page_query_param = "page"


class UserModelView(ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSer
    # 如果未设置全局，需局部配置
    # filter_backends = [OrderingFilter, DjangoFilterBackend]
    ordering_fields = ('age', 'hight')
    filter_fields = ('username', 'age', 'home')
    pagination_class = MyPage
